<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php $this->load->view('include/html_head')?>
</head>
<body>
<div id="wrapper">
	<?php $this->load->view('include/header')?>
	<?php $this->load->view('include/menu')?>
	<div id="page">
		<div id="content">
		<?php $this->load->view('include/sub_navi')?>
			<div class="post">
			<form action="<?php echo BACKEND_SOCIETY_ANNOUNCEMENT_EDIT_POST_PATH ?>" id='edit_form' method='post'>
				<p class="meta">公告管理</p>
				<div class="entry">
				<input type='hidden' id="id" name="id" value="<?php echo set_value('id', $announcement['id'])?>"/>
			    <input type='hidden' id="is_published" name="is_published" value="<?php echo set_value('is_published', $announcement['is_published'])?>"/>
			    	<table class='full'>
				        <tbody>
						  	<tr>
						  	<th>标题</th>
				  			<td><input type="text" id='title' name='title' class="validate[required,minSize[2],maxSize[20]] text-input" value="<?php echo set_value('title', $announcement['title'])?>" />
				  			<?php echo form_error('title', '<div class="error">', '</div>'); ?>
				  			</td>
							</tr>
					  	</tbody>
				  	</table>
					
			  		<textarea id='contents' cols="90" name='contents' class="validate[required,minSize[10],maxSize[200]] text-field"><?php echo set_value('contents', $announcement['contents'])?></textarea>
			  		<?php echo form_error('contents', '<div class="error">', '</div>'); ?>
			  		<script type="text/javascript">
			        	var contents_editor = CKEDITOR.replace('contents', { toolbar : 'Basic' });
			        	CKFinder.setupCKEditor(contents_editor, '<?php echo PLUGIN_CKFINDER_FOLDER ?>');
			        	
			        	contents_editor.on("instanceReady", function(){
							//set keyup event
							this.document.on("keyup", updateTextArea);
							//and paste event
							this.document.on("paste", updateTextArea);
							
							this.document.on("blur", check);
						});
						
						function updateTextArea() {
							CKEDITOR.instances.contents.updateElement(); 
						}
						
						function check() {
							$("#contents").focus();
							$("#contents").blur();
						}        	
			    	</script>
					
					<script>
					$("button#post").live('click', function() {
						$("#is_published").val(<?php echo IS_PUBLISHED ?>);
					});
					$("button#save").live('click', function() {
						$("#is_published").val(<?php echo NOT_PUBLISHED ?>);
					});
					</script>
					<?php if ($announcement['id'] == '') :?>
					<button type='submit' id='post' >发布</button>
					<button type='submit' id='save' >保存</button>
				    <?php elseif ($announcement['is_published'] == NOT_PUBLISHED):?>
				    <a class='anchor_button' id='post' href="<?php echo BACKEND_SOCIETY_ANNOUNCEMENT_PUBLISH_PATH . $announcement['id']?>" >发布</a>
					<button type='submit' id='save' >保存</button>
					<?php elseif ($announcement['is_published'] == IS_PUBLISHED):?>
					<button id='post' type='submit' >保存</button>
					<?php endif;?>
					<a class='anchor_button' onclick="history.back(-1);" >返回</a>
				</div>
			</form>
			</div>
			<div style="clear: both;">&nbsp;</div>
		</div>
		<!-- end #content -->
		<?php $this->load->view('include/side_bar')?>
		<div style="clear: both;">&nbsp;</div>
	</div>
	<!-- end #page -->
</div>
<?php $this->load->view('include/footer_content')?>
<?php $this->load->view('include/footer')?>
</body>
</html>
